package com.hebg3.weixin.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.hebg3.weixin.po.User;
import com.hebg3.weixin.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService us;

	@RequestMapping("/login")
	public String login(Model model, HttpServletRequest request,
			@RequestParam(required = false) String username,
			@RequestParam(required = false) String pwd) {

		User u = us.login(username, pwd);
		if (null != u) {
			request.getSession().setAttribute("lu", u);
			return "/success";
		} else {
			return "/login";
		}
	}
	
	@RequestMapping("/logout")
	public String logout(HttpServletRequest request){
		request.getSession().invalidate();
		return "/login";
	}

}
